{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item {
        float: left;
        position: relative;
        width: 110px;
        height: 110px;
        margin: 0 20px 20px 0;
        padding: 4px;
    }
    
    .file-item .info {
        overflow: hidden;
    }
    
    .uploader-list {
        width: 100%;
        overflow: hidden;
    }
</style>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑用户</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal" name="edit_member" id="edit_member" method="post" action="{:url('edit_member')}">
                            <input type="hidden" name="id" value="{$member.id}">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">昵称：</label>
                                <div class="input-group col-sm-4">
                                    <input id="nickname" type="text" class="form-control" name="nickname" value="{$member.nickname}" placeholder="请输入昵称">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">头像：</label>
                                <div class="input-group col-sm-4">
                                    <input type="hidden" id="data_photo" name="head_img" value="{$member.head_img}">
                                    <div id="fileList" class="uploader-list" style="float:right"></div>
                                    <div id="imgPicker" style="float:left">选择图片</div>
                                    <img id="img_data" class="img-circle" height="80px" width="80px" style="float:left;margin-left: 50px;margin-top: -10px;" src="/uploads/face/{$member.head_img}" onerror="this.src='/static/admin/images/head_default.gif'" />
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">性别：</label>
                                <div class="input-group col-sm-4">
                                    <input type="radio" name='sex' value="1" {if condition="$member['sex'] eq 1 " }checked{/if} />男&nbsp;&nbsp;
                                    <input type="radio" name='sex' value="2" {if condition="$member['sex'] eq 2 " }checked{/if} />女
                                </div>
                            </div>
                            
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">出生日期：</label>
                                <div class="input-group col-sm-4">
                                    <input id="birth" type="text" class="form-date" value="{$member['birth']}" name="birth" placeholder="请输入出生日期">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">家乡-省：</label>
                                <div class="input-group col-sm-4">
                                    <select class="form-control m-b chosen-select" name="home_province" id="province_id">
                                        <option value="">==请选择省==</option>
                                        {if !empty($areas)}
                                        {foreach name="areas" item="vo"}
                                        <option value="{$vo.id}" {if condition="$member['home_province'] eq $vo['id']"}selected{/if}>{$vo.name}</option>
                                        {/foreach}
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">家乡-市：</label>
                                <div class="input-group col-sm-4">
                                    <select class="form-control m-b chosen-select" name="home_city" id="city_id">
                                        <option value="">==请选择市==</option>
                                        {if !empty($citys)}
                                        {foreach name="citys" item="vo"}
                                        <option value="{$vo.id}" {if condition="$member['home_city'] eq $vo['id']"}selected{/if}>{$vo.name}</option>
                                        {/foreach}
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">学历：</label>
                                <div class="input-group col-sm-4">
                                    <select class="form-control m-b chosen-select" name="offer_id" id="offer_id">
                                    <option value="">==请选择学历==</option>
                                    {if !empty($offer)}
                                        {foreach name="offer" item="vo"}
                                            <option value="{$vo.id}" {if condition="$member['offer_id'] eq $vo['id']"}selected{/if}>{$vo.offer_name}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">毕业院校：</label>
                                <div class="input-group col-sm-4">
                                    <input id="college" type="text" class="form-control" name="college" value="{$member.college}" placeholder="请输入毕业院校">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">工作单位：</label>
                                <div class="input-group col-sm-4">
                                    <input id="work" type="text" class="form-control" name="work" value="{$member.work}" placeholder="请输入工作单位">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">身高：</label>
                                <div class="input-group col-sm-4">
                                    <input id="height" type="number" class="form-control" name="height" value="{$member.height}" placeholder="请输入身高">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">择偶-年龄上限：</label>
                                <div class="input-group col-sm-4">
                                    <input id="max_age" type="number" class="form-control" name="max_age" value="{$member.max_age}" placeholder="请输入年龄上限">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">择偶-年龄下限：</label>
                                <div class="input-group col-sm-4">
                                    <input id="min_age" type="number" class="form-control" name="min_age" value="{$member.min_age}" placeholder="请输入年龄下限">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">择偶-学历：</label>
                                <div class="input-group col-sm-4">
                                    <select class="form-control m-b chosen-select" name="other_offer_id" id="other_offer_id">
                                        <option value="">==请选择学历==</option>
                                        {if !empty($offer)}
                                        {foreach name="offer" item="vo"}
                                        <option value="{$vo.id}" {if condition="$member['other_offer_id'] eq $vo['id']"}selected{/if}>{$vo.offer_name}以上</option>
                                        {/foreach}
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">配偶-身高上限：</label>
                                <div class="input-group col-sm-4">
                                    <input id="max_height" type="number" class="form-control" name="max_height" value="{$member.max_height}" placeholder="请输入身高上限">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">配偶-身高下限：</label>
                                <div class="input-group col-sm-4">
                                    <input id="min_height" type="number" class="form-control" name="min_height" value="{$member.min_height}" placeholder="请输入身高下限">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">爱好：</label>
                                <div class="input-group col-sm-4">
                                    {volist name="habits" id="vo"}
                                    <input type="checkbox" name="habit[]" value="{$vo.id}"  {in  name="$vo['id']" value="$member.habit"}checked{/in} >{$vo.name}
                                    {/volist}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">家庭介绍：</label>
                                <div class="input-group col-sm-4">
                                    <textarea id="home_intro" type="text" class="form-control" name="home_intro" placeholder="请输入家庭介绍">{$member.home_intro}</textarea>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">个人介绍：</label>
                                <div class="input-group col-sm-4">
                                    <textarea id="self_intro" type="text" class="form-control" name="self_intro" placeholder="请输入个人介绍">{$member.self_intro}</textarea>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">审核状态：</label>
                                <div class="col-sm-6">
                                    <div class="radio i-checks">
                                        <input type="radio" name='status' value="1" {if condition="$member['status'] eq 1 " }checked{/if}/>通过&nbsp;&nbsp;
                                        <input type="radio" name='status' value="0" {if condition="$member['status'] eq 0 " }checked{/if}/>拒绝
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                    <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {include file="public/footer" /}
    <script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

    <script type="text/javascript">
    //时间选择器
    laydate.render({
            elem: '#birth'
        });

        var $list = $('#fileList');
        //上传图片,初始化WebUploader
        var uploader = WebUploader.create({

            auto: true, // 选完文件后，是否自动上传。   
            swf: '/static/admin/webupload/Uploader.swf', // swf文件路径 
            server: "{:url('Upload/uploadface')}", // 文件接收服务端。
            duplicate: true, // 重复上传图片，true为可重复false为不可重复
            pick: '#imgPicker', // 选择文件的按钮。可选。

            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/jpg,image/jpeg,image/png'
            },

            'onUploadSuccess': function(file, data, response) {
                $("#data_photo").val(data._raw);
                $("#img_data").attr('src', '/uploads/face/' + data._raw).show();
            }
        });

        uploader.on('fileQueued', function(file) {
            $list.html('<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">正在上传...</p>' +
                '</div>');
        });

        // 文件上传成功
        uploader.on('uploadSuccess', function(file) {
            $('#' + file.id).find('p.state').text('上传成功！');
        });

        // 文件上传失败，显示上传出错。
        uploader.on('uploadError', function(file) {
            $('#' + file.id).find('p.state').text('上传出错!');
        });

        $('#province_id').change(function () {
            // console.log($(this).val());
            var province_id = $('#province_id').val();
            $.get('{:url("Member/member_area")}?id='+province_id, function (res) {
                if(res){
                    var html = '';
                    for (var i=0 ;i<res.length;i++){
                        html += "<option value="+res[i]['id']+">"+res[i]['name']+"</option>";
                    }
                    $('#city_id').html(html);
                }
            });
        })
        //提交
        $(function() {
            $('#edit_member').ajaxForm({
                beforeSubmit: checkForm,
                success: complete,
                dataType: 'json'
            });

            function checkForm() {
                // if ('' == $.trim($('#account').val())) {
                //     layer.msg('请输入账号', {
                //         icon: 2,
                //         time: 1500,
                //         shade: 0.1
                //     }, function(index) {
                //         layer.close(index);
                //     });
                //     return false;
                // }

                if ('' == $.trim($('#nickname').val())) {
                    layer.msg('请输入昵称', {
                        icon: 2,
                        time: 1500,
                        shade: 0.1
                    }, function(index) {
                        layer.close(index);
                    });
                    return false;
                }

                
                if ('' == $.trim($('#offer_id').val())) {
                    layer.msg('请选择学历', {
                        icon: 2,
                        time: 1500,
                        shade: 0.1
                    }, function(index) {
                        layer.close(index);
                    });
                    return false;
                }

            }

            function complete(data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 1500,
                        shade: 0.1
                    }, function(index) {
                        window.location.href = "{:url('member/index')}";
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 1500,
                        shade: 0.1
                    });
                    return false;
                }
            }
        });
    </script>
</body>

</html>